package models

import (
	"time"

	"github.com/beego/beego/v2/client/orm"
)

type WaterLevelData struct {
	SiteName     string    `orm:"column(site_name);size(255)"`
	RegionalName string    `orm:"column(regional_name);size(255)"`
	SiteCode     string    `orm:"column(site_code);size(255)"`
	WatchTime    time.Time `orm:"column(watch_time);type(datetime)"`
	WaterLevel   float64   `orm:"column(water_level);size(255)"`
}

func init() {
	// Need to register model in init
	orm.RegisterModel(new(WaterLevelData))
}

func (wl *WaterLevelData) FormatRisk() string {
	if wl.WaterLevel < 0.27 {
		return "low"
	} else if wl.WaterLevel < 0.4 {
		return "medium"
	} else if wl.WaterLevel < 0.6 {
		return "high"
	} else {
		return "severe"
	}
}
